from strategy import Strategy

class MovingAverage(Strategy):
  def Run(self, Open, High, Low, Close):
    fast = lambda x: self.Average(Close, 4, x)
    slow = lambda x: self.Average(Close, 48, x)
    #print "close=%d"%(Close(0))
    #print "fast(0)=%d, slow(0)=%d"%(fast(0), slow(0))
    if self.CrossOver(fast, slow):
      self.Buy(Close(0))
      print "[%s] Fast(%d) cross over Slow(%d): Buy @%d"%(\
        self.bars[self.current_index].time, fast(0), slow(0), Close(0))
    elif self.CrossOver(slow, fast):
      self.Sell(Close(0))
      print "[%s] Fast(%d) cross under Slow(%d): Sell@%d"%(\
        self.bars[self.current_index].time, fast(0), slow(0), Close(0))

  